package com.adroiti.texasholdem.engine.combinations;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.adroiti.texasholdem.Card;

public abstract class NofKind extends AbstractCombination {

	private High high;

	public NofKind(High high){
		this.high = high;
	}
	
	protected int getNKindRank(List<Card> player, List<Card> table, int num, int threshold, boolean noHigh) {
		List<Card> cards = new ArrayList<Card>();
		cards.addAll(table);
		cards.addAll(player);

		Collections.sort(cards, Collections.reverseOrder());
		
		if(threshold == 0){
			threshold = 15;
		}

		for (int i = 0, number = 0; i < cards.size() - 1; i++) {
			if (cards.get(i).getRank() < threshold && cards.get(i).getRank() == cards.get(i + 1).getRank()) {
				number++;
			} else
				number = 0;
			if (number == num - 1) {
				if(noHigh){
					return cards.get(i).getRank();
				}
				else return high.getRank(player, table)*cards.get(i).getRank();
			}

		}

		return 0;
	}
	
	protected int getNKindRank(List<Card> player, List<Card> table, int num, int threshold) {
		return getNKindRank(player, table, num, threshold, false);
	}
	
}
